package com.pzl.demo2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.pzl.demo2.adapter.PS2ToUSBAdapter;
import com.pzl.demo2.interfaces.IPS2Port;
import com.pzl.demo2.interfaces.IUSBPort;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        logic();
    }

    private void logic() {
        //1.我现在有一个PS2接口
        IPS2Port ps2Port = new IPS2Port() {
            @Override
            public void workWithPS2() {
                System.out.println("PS2工作中");
            }
        };

        //2.但是我需要的是一个USB接口啊,对我(client)来说，我只认识USB接口
        //3.经过PS2ToUSB的转换，PS2接口变成了USB接口
        IUSBPort usbPort = new PS2ToUSBAdapter(ps2Port);

        usbPort.workWithUSB();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
